let  leaveModel  = require("../model/leaveTable");

module.exports = {
    leaveQuery:(params)=>{
        return  leaveModel.find(params);
    },
    leaveQueryAll:(params,skip,limit)=>{//查询所有
        return  leaveModel.find(params).skip(skip).limit(limit);
    },
    leaveQueryAllCount:(params)=>{//查询所有总数
        return  leaveModel.count(params);
    },
    leaveUpdate:(params1,params2)=>{//更新
        return  leaveModel.updateMany(params1,params2);
    },
    leaveAdd:(data)=>{
        return  leaveModel.insertMany([data]);
    },
    leaveAddMany:(list)=>{
        return  leaveModel.insertMany(list);
    },
    //group 分组
    leaveGroup:(key)=>{//根据key进行来分组统计
        return  leaveModel.aggregate([
            {
                $group:
                {
                    _id:"$"+key,//_id不能变  可以是username 也可以是type
                    count: { $sum: 1 }//类似于.count 但这是是管道函数　　所以还需要加上$sum关键词
                },
            },
        ])
    }
}